﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;
using System.IO;
#endregion Using Statements

namespace CakeRaid
{
    class Enemy_Beetle : Enemy
    {
        #region Constructor
        public Enemy_Beetle(ImageObject imageObject, ImageObject effects, int health, int damage, float speed, Path path, Cake cakeTemp, HUD hud)
            : base(imageObject, effects, health, damage, speed, path, cakeTemp, hud)
        {
            StartHealth = Var.BEETLE_HEALTH;
            Damage = Var.BEETLE_DAMAGE;
            Speed = Var.BEETLE_SPEED;
        }
        #endregion Constructor

        #region Methods

        #region Move
        public override void MoveBy(float num)
        {
            if (base.Behavior.Equals(BehaviorState.FollowPath))
            {
                #region Default Pathing
                // Move Left
                if (path.GetNextTile(currentTile).Center.X < Center.X)
                {
                    // If rounding a corner
                    if (Center.X - num < path.GetNextTile(currentTile).Center.X)
                    {
                        currentTile++;
                        // How far off it went over center
                        float distOff = num - (Center.X - path.GetTile(currentTile).Center.X);
                        X -= num - distOff;
                        MoveBy(distOff);
                    }
                    // Otherwise move normally
                    else
                    {
                        Image.Rotation = ImageObject.LEFT;
                        X -= num;
                        if (Center.X == path.GetNextTile(currentTile).Center.X)
                            currentTile++;
                    }
                }
                // Move up
                else if (path.GetNextTile(currentTile).Center.Y < Center.Y)
                {
                    // If rounding a corner
                    if (Center.Y - num < path.GetNextTile(currentTile).Center.Y)
                    {
                        currentTile++;
                        // How far off it went over center
                        float distOff = num - (Center.Y - path.GetTile(currentTile).Center.Y);
                        Y -= num - distOff;
                        MoveBy(distOff);
                    }
                    // Otherwise move normally
                    else
                    {
                        Image.Rotation = ImageObject.UP;
                        Y -= num;
                        if (Center.Y == path.GetNextTile(currentTile).Center.Y)
                            currentTile++;
                    }
                }
                // Move Right
                else if (path.GetNextTile(currentTile).Center.X > Center.X)
                {
                    // If rounding a corner
                    if (Center.X + num > path.GetNextTile(currentTile).Center.X)
                    {
                        currentTile++;
                        // How far off it went over center
                        float distOff = num - (path.GetTile(currentTile).Center.X - Center.X);
                        X += num - distOff;
                        MoveBy(distOff);
                    }
                    // Otherwise move normally
                    else
                    {
                        Image.Rotation = ImageObject.RIGHT;
                        X += num;
                        if (Center.X == path.GetNextTile(currentTile).Center.X)
                            currentTile++;
                    }
                }
                // Move down
                else if (path.GetNextTile(currentTile).Center.Y > Center.Y)
                {
                    // If rounding a corner
                    if (Center.Y + num > path.GetNextTile(currentTile).Center.Y)
                    {
                        currentTile++;
                        // How far off it went over center
                        float distOff = num - (path.GetTile(currentTile).Center.Y - Center.Y);
                        Y += num - distOff;
                        MoveBy(distOff);
                    }
                    // Otherwise move normally
                    else
                    {
                        Image.Rotation = ImageObject.DOWN;
                        Y += num;
                        if (Center.Y == path.GetNextTile(currentTile).Center.Y)
                            currentTile++;
                    }
                }
                #endregion Default Pathing
            }
            else if (base.Behavior.Equals(BehaviorState.MoveToTower))
            {
                #region Focused Path to Tower
                // Move Left
                if (focusedTower.Center.X < Center.X)
                {
                    Image.Rotation = ImageObject.LEFT;
                    X -= num;
                    if (Center.X == focusedTower.Center.X)
                        currentTile++;
                }
                // Move up
                else if (focusedTower.Center.Y < Center.Y)
                {
                    Image.Rotation = ImageObject.UP;
                    Y -= num;
                    if (Center.Y == focusedTower.Center.Y)
                        currentTile++;
                }
                // Move Right
                else if (focusedTower.X > Center.X)
                {
                    Image.Rotation = ImageObject.RIGHT;
                    X += num;
                    if (Center.X == focusedTower.Center.X)
                        currentTile++;
                }
                // Move down
                else if (focusedTower.Y > Center.Y)
                {
                    Image.Rotation = ImageObject.DOWN;
                    Y += num;
                    if (Center.Y == focusedTower.Center.Y)
                        currentTile++;
                }
                #endregion Focused Path to Tower
            }
            else if (base.Behavior.Equals(BehaviorState.MoveFromTower))
            {
                #region Focused Path from Tower
                // Move Left
                if (path.GetNextTile(currentTile).Center.X < Center.X)
                {
                    Image.Rotation = ImageObject.LEFT;
                    X -= num;
                    if (Center.X == path.GetNextTile(currentTile).Center.X)
                        currentTile++;
                }
                // Move up
                else if (path.GetNextTile(currentTile).Center.Y < Center.Y)
                {
                    Image.Rotation = ImageObject.UP;
                    Y -= num;
                    if (Center.Y == path.GetNextTile(currentTile).Center.Y)
                        currentTile++;
                }
                // Move Right
                else if (path.GetNextTile(currentTile).Center.X > Center.X)
                {
                    Image.Rotation = ImageObject.RIGHT;
                    X += num;
                    if (Center.X == path.GetNextTile(currentTile).Center.X)
                        currentTile++;
                }
                // Move down
                else if (path.GetNextTile(currentTile).Center.Y > Center.Y)
                {
                    Image.Rotation = ImageObject.DOWN;
                    Y += num;
                    if (Center.Y == path.GetNextTile(currentTile).Center.Y)
                        currentTile++;
                }
                #endregion Focused Path from Tower
            }
        }
        #endregion Move

        #endregion Methods
    }
}